/**
 * @Author:Geln Yang
 * @Created:2008-8-7
 * $ Revision: 1.0 $
 * $ Author: Geln Yang $
 * $ Date: 2008-8-7 $
 */
package org.geln.web.webwork.convert;

import java.math.BigDecimal;
import java.util.Map;

import com.opensymphony.webwork.util.WebWorkTypeConverter;
import com.opensymphony.xwork.XworkException;

/**
 * @Author:Geln Yang
 * @Created:2008-8-7
 */
public class BigDecimalConvert extends WebWorkTypeConverter {

	public Object convertFromString(Map context, String[] values, Class toClass) {
		BigDecimal result = null;
		if(toClass == BigDecimal.class){
			try {
				result = new BigDecimal(values[0]);
			} catch (NumberFormatException e) {
				throw new XworkException("cound not parse number.",e);
			}
		}
		return result;
	}
	
	public String convertToString(Map context, Object o) {
		String result = null;
        if (o instanceof BigDecimal) {
            result = ((BigDecimal) o).toString();
        }
        return result;
	}

}
